import os
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image

data_path = 'G:/MTI_database/Vaihingen/raw_edge'
file_name = os.listdir(data_path)
# _edge = np.load('G:/MTI_database/NYUD_MT/edge/train_0.npy').astype(np.float32)
for i in file_name:
    img = Image.open(data_path+'/'+i)
    np_img = np.asarray(img)
    new_img = np_img.mean(axis=2)
    new_img[new_img != 0] = 1
    new_img= 1 - new_img
    np.save('G:/MTI_database/Vaihingen/edge'+'/'+i.replace('.tif','.npy'), new_img)

# data_path = 'G:/MTI_database/Vaihingen/image'
# file_name = os.listdir(data_path)
# with open('G:/MTI_database/Vaihingen/gt_sets/train.txt', 'w') as f:
#     for i in file_name[:30]:
#         f.write(i+'\n')
# with open('G:/MTI_database/Vaihingen/gt_sets/val.txt', 'w') as f:
#     for i in file_name[30:]:
#         f.write(i+'\n')